{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6ef2dff2",
   "metadata": {},
   "source": [
    "# 1.2.1创建张量 #\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fac08f7",
   "metadata": {},
   "source": [
    "## 1.2.1.1 指定数据创建张量 ##"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "228bc786",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([2., 3., 4.])"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "Tensor1 = torch.tensor([2.0,3.0,4.0])\n",
    "Tensor1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7f52dbc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[2., 3., 4.],\n",
       "        [3., 4., 5.]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tensor2 = torch.tensor([[2.,3.,4.],\n",
    "                        [3.,4.,5.]])\n",
    "Tensor2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3c324f59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[1., 2.],\n",
       "         [2., 3.]],\n",
       "\n",
       "        [[1., 2.],\n",
       "         [7., 8.]]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tensor3 = torch.tensor([[[1.,2.],[2.,3.]],[[1.,2.],[7.,8.]]])\n",
    "Tensor3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcb808ad",
   "metadata": {},
   "source": [
    "## 1.2.1.2 指定形状创建张量 ##"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c5bd5bf0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[0., 0., 0.],\n",
       "        [0., 0., 0.]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "zeroTensor = torch.zeros((2,3))\n",
    "zeroTensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da88367c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
